/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2020年11月3日
 */
package com.massyframework.beanskin.launching.web;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;

/**
 * @author huangkh
 *
 */
public class ServletContextListenerDispatcher extends ServletContextListenerTracker 
	implements ServletContextListener,
		ServletContextAttributeListener,
		HttpSessionActivationListener,
		HttpSessionAttributeListener,
		HttpSessionBindingListener,
		HttpSessionIdListener,
		HttpSessionListener{
	

	/**
	 * 
	 */
	public ServletContextListenerDispatcher() {
	}

	@Override
	public synchronized void contextInitialized(ServletContextEvent sce) {
		this.foreachListener(ServletContextListener.class,  listener -> listener.contextInitialized(sce));
		
	}

	@Override
	public synchronized void contextDestroyed(ServletContextEvent sce) {
		this.foreachListener(ServletContextListener.class,  listener -> listener.contextDestroyed(sce));
	}
	
	

	@Override
	public void sessionCreated(HttpSessionEvent se) {
		this.foreachListener(HttpSessionListener.class,  listener-> listener.sessionCreated(se));
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		this.foreachListener(HttpSessionListener.class,  listener-> listener.sessionDestroyed(se));
		
	}

	@Override
	public void sessionIdChanged(HttpSessionEvent event, String oldSessionId) {
		this.foreachListener(HttpSessionIdListener.class,  listener-> listener.sessionIdChanged(event, oldSessionId));
	}

	@Override
	public void valueBound(HttpSessionBindingEvent event) {
		this.foreachListener(HttpSessionBindingListener.class,  listener-> listener.valueBound(event));
		
	}

	@Override
	public void valueUnbound(HttpSessionBindingEvent event) {
		this.foreachListener(HttpSessionBindingListener.class,  listener-> listener.valueUnbound(event));
	}

	@Override
	public void attributeAdded(HttpSessionBindingEvent event) {
		this.foreachListener(HttpSessionAttributeListener.class,  listener-> listener.attributeAdded(event));
	}

	@Override
	public void attributeRemoved(HttpSessionBindingEvent event) {
		this.foreachListener(HttpSessionAttributeListener.class,  listener-> listener.attributeRemoved(event));
	}

	@Override
	public void attributeReplaced(HttpSessionBindingEvent event) {
		this.foreachListener(HttpSessionAttributeListener.class,  listener-> listener.attributeReplaced(event));
		
	}

	@Override
	public void sessionWillPassivate(HttpSessionEvent se) {
		this.foreachListener(HttpSessionActivationListener.class,  listener-> listener.sessionWillPassivate(se));
		
	}

	@Override
	public void sessionDidActivate(HttpSessionEvent se) {
		this.foreachListener(HttpSessionActivationListener.class,  listener-> listener.sessionDidActivate(se));
		
	}

	@Override
	public void attributeAdded(ServletContextAttributeEvent event) {
		this.foreachListener(ServletContextAttributeListener.class,  listener-> listener.attributeAdded(event));
		
	}

	@Override
	public void attributeRemoved(ServletContextAttributeEvent event) {
		this.foreachListener(ServletContextAttributeListener.class,  listener-> listener.attributeRemoved(event));
		
	}

	@Override
	public void attributeReplaced(ServletContextAttributeEvent event) {
		this.foreachListener(ServletContextAttributeListener.class,  listener-> listener.attributeReplaced(event));
	}
		
}
